﻿
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHostedService<TestHostService>();
var app = builder.Build();
app.Run();



public class TestHostService : IHostedService
{
    public async Task StartAsync(CancellationToken cancellationToken)
    {
        while (true)
        {
            await Task.Delay(3000);
            Console.WriteLine("输出123");
        }
    }

    public Task StopAsync(CancellationToken cancellationToken)
    {
        throw new NotImplementedException();
    }
}